package com.runvp.rest.biz;

import java.util.List;

import com.runvp.common.annotation.ParamValid;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.runvp.common.annotation.Log;
import com.runvp.common.enums.BusinessType;
import com.runvp.service.biz.domain.BizSite;
import com.runvp.service.biz.service.IBizSiteService;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.common.core.page.TableDataInfo;

/**
 * 场地Controller
 * 
 * @author runvp
 * @date 2022-09-18
 */
@Controller
@RequestMapping("/biz/site")
public class BizSiteController extends BaseController {
    private String prefix = "biz/site";

    @Autowired
    private IBizSiteService bizSiteService;

    @RequiresPermissions("biz:site:view")
    @GetMapping()
    public String site()
    {
        return prefix + "/site";
    }

    /**
     * 查询场地列表
     */
    @RequiresPermissions("biz:site:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizSite bizSite) {
        startPage();
        bizSite.setTenantId(getUserIdFilterAdmin());
        List<BizSite> list = bizSiteService.selectBizSiteList(bizSite);
        return getDataTable(list);
    }

    /**
     * 导出场地列表
     */
    @RequiresPermissions("biz:site:export")
    @Log(title = "场地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizSite bizSite) {
        List<BizSite> list = bizSiteService.selectBizSiteList(bizSite);
        ExcelUtil<BizSite> util = new ExcelUtil<BizSite>(BizSite.class);
        return util.exportExcel(list, "场地数据");
    }

    /**
     * 新增场地
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存场地
     */
    @ParamValid
    @RequiresPermissions("biz:site:add")
    @Log(title = "场地", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizSite bizSite) {
        bizSite.setTenantId(getUserId());
        return toAjax(bizSiteService.insertBizSite(bizSite));
    }

    /**
     * 修改场地
     */
    @RequiresPermissions("biz:site:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizSite bizSite = bizSiteService.selectBizSiteById(id);
        mmap.put("bizSite", bizSite);
        return prefix + "/edit";
    }

    /**
     * 修改保存场地
     */
    @ParamValid
    @RequiresPermissions("biz:site:edit")
    @Log(title = "场地", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizSite bizSite) {
        return toAjax(bizSiteService.updateBizSite(bizSite));
    }

    /**
     * 删除场地
     */
    @RequiresPermissions("biz:site:remove")
    @Log(title = "场地", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizSiteService.deleteBizSiteByIds(ids));
    }
}
